<html>
<head>
  <title>a2_sample4.php</title>
</head>
<body bgcolor="#ffffff" text="#000000">
<pre>
&lt;html&gt;
 &lt;head&gt;
  &lt;title&gt;PHP Demo A2.4&lt;/title&gt;
 &lt;/head&gt;

&lt;body&gt;

&lt;h1&gt;Demo A2.4&lt;/h1&gt;

&lt;p&gt;b


&lt;?php

//  phpinfo();

  echo &quot;&lt;p&gt;&quot; . `/bin/date` . &quot;&lt;p&gt;&quot;;

// import the PHP code that make it so easy to access the remote server
  require('HttpClient.class.php');

// create a &quot;client&quot; object which will access the desired web site
  $client = new HttpClient('media.jcu.edu.au');

// leave debug off UNLESS you have problems
  $client-&gt;setDebug(false);

// grab a news item
  if ( ! $client-&gt;get('/story.cfm?id=777 ') ) {
    die( 'An error occurred: ' . $client-&gt;getError() );
  }

// copy the web page contents into $pageContents and display
  $pageContents = $client-&gt;getContent();

// Note that the item we want is between comment tags
//     &lt;!-- start content --&gt;
//     &lt;!-- end content --&gt;
//
// This is essentially a text extraction operation where these comments are
// the delimiters that surround the desired text.  I figured that regular
// expressions are going to provide a clean answer.
//
// On www.php.net, I did a function search for PHP &quot;regexp&quot; and then
// &quot;preg_match&quot; and decide to use preg_match.  Read the examples and, in
// particular, the item http://au3.php.net/preg_match_all
//
// Note that a regular expression convention is to use the first character
// of the control string be the delimiter of the pattern.  I do not see any
// ':' chars in the HTML of the above comment strings so I choose ':' as a
// delimiter.
//
// The following regexp pattern should select the text between the HTML
// comments i.e. the news item of interest:
//
//    ':&lt;!-- start content --&gt;(.*)&lt;!-- end content --&gt;:';
//
// where the text that we want to extract is represented inside parentheses.
// We have a .* inside the () characters so that means we want all characters
// between the two delimiters.

  $News_Item_Pattern = ':&lt;!-- start content --&gt;(.*)&lt;!-- end content --&gt;:';

  $Nitems = preg_match_all( $News_Item_Pattern, $pageContents, $News_Items, PREG_PATTERN_ORDER );

  print 'Extracted ' . $Nitems . ' items.  A dump of the raw HTML follows';

//echo '&lt;p&gt; &lt;hr&gt;';
//print $News_Items[1][0];

echo '&lt;p&gt; &lt;hr&gt; &lt;pre&gt;';

  $html_dump=str_replace( '&lt;', '&amp;lt;', $News_Items[1][0] );
  print $html_dump;

echo '&lt;/pre&gt;';
?&gt;
 
&lt;p&gt;

&lt;hr&gt;

&lt;/body&gt;
&lt;/html&gt;

</pre>
<hr>
syntax highlighted by <a href="http://www.palfrader.org/code2html">Code2HTML</a>, v. 0.9.1
</body>
</html>
